soda()
	._page('iam_account')
	._api('/v1/iam/account')
	._query(['realName^like^', 'authAccount^like^', 'userType^eq^-1', 'authType^eq^-1'])
	._orderBy(['createTime^desc'])
	._run((unit) => {
		// 表单配置
		unit.templateForm['verify'] = ["authAccount", "realName"];
		unit.templateForm['items'] = [
			{code: 1, name:'authAccount', title:'电话号码', placeholder:'请输入电话号码', attr: 'maxlength=20'},
			{code: 1, name:'realName', title:'真实姓名', placeholder:'请输入真实姓名', attr: 'maxlength=10'},
			{code: 2, name:'state', title:'状态', options: unit.globalConstant['gender']},
			{code: 1, name:'email', title:'电子邮件', placeholder:'请输入电子邮件', attr: 'maxlength=50'}
		];
		
		// 表格基础配置
		unit.templateTable['cols'] = [
			{fixed: 'left', field: 'userType', title: '账号类型', minWidth: 100},
			{fixed: 'left', field: 'authType', title: '登录类型', minWidth: 100},
			{fixed: 'left', field: 'authAccount', title: '登录号', minWidth: 120},
			{field: 'realName', title: '姓名', minWidth: 120},
			{field: 'gender', title: '性别'},
			{field: 'openId', title: 'openId', minWidth: 120},
			{field: 'unionId', title: 'unionId', minWidth: 120},
			{field: 'state', title: '状态',templet: function (obj) {
			    return unit.sdFormat['json']['get'](unit.globalConstant['enableState'], obj.state, 'value').title;
			}},
			{field: 'createTime', title: '注册时间', minWidth: 120},
			{fixed: 'right', title: '操作', minWidth: 120, toolbar: unit.sysApplication['btns']['right']()},
		];
		unit.templateTable['bar'] = (bar) => {
			unit.templateDialog[bar.event]();
		}
		unit.templateTable['tool'] = (tool) => {
			unit.templateDialog[tool.event](tool.data);
		}
		// 表格查询配置
		unit.templateTable['search']['components'] = [
			{code:1, name:"authAccount", title:"登录账号", placeholder:"请输入要查询的关键字"},
			{code:1, name:"realName", title:"姓名", placeholder:"请输入要查询的关键字"},
			{code:3, name:"authType", title:"登录类型", options: unit.globalConstant['authType']},
			{code:3, name:"userType", title:"用户类型", options: unit.globalConstant['accountType']}
		]
		unit.templateTable['search']['submit'] = (data) => {
			unit.sdTable.reload(unit.el['table'], {
				where: unit.sdFormat['query'](unit.filter['vo'], data)
			});
		}
		
		unit.templateDialog['form'] = (data) => {
			unit.sdDialog.form({
				title: data ? '修改' : "创建",
				height: '500px',
				init() {
					unit.sdForm['init']['form'](unit.templateForm, data);
				},
				opt(index) {
					// 获取form
					let form = unit.sdForm['get'](unit.el['form'], unit.templateForm['verify']);
					
					// 校验数据
					if (!form.check) {
						unit.sdDialog['tips']['warning'](form.message);
						return false;
					}
					
					// 数据处理
					let val = form.data;
					val['gender'] = val['gender'] || '保密';
			
					let param = {
						url: unit.api['crud'] + '/platform',
						data: val,
						tips: true,
						callback() {
							unit.sdDialog['close'](index);
							unit.sdTable['reload'](unit.el.table);
						}
					}
					// 操作
					data ? unit.sdHttp['put'](param, data.id) : unit.sdHttp['post'](param);
				}
			})
		}
		unit.templateDialog['create'] = unit.templateDialog['form'];
		unit.templateDialog['update'] = unit.templateDialog['form'];
		unit.templateDialog['delete'] = (data) => {
			unit.sdDialog.confirm({
				title: "是否要删除这条数据?",
				submit() {
					let param = {
						url: unit.api['crud'],
						callback() {
							unit.sdTable['reload'](unit.el.table)
						}
					}
					unit.sdHttp['delete'](param, data.id);
				}
			});
		}
		unit.sdTable['render'](unit.templateTable);
	})
